﻿using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Text;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using QRCodePass.Core.Models;
using QRCodePass.Core.Repositories;

namespace QRCodePass.EntityFrameworkCore.Seed
{
    public static class InitClaimData
    {
        public static IApplicationBuilder UseInitClaimData(
            this IApplicationBuilder builder)
        {
            ClaimsStore.AllClaims = new List<Claim>()
            {
                new Claim("Create Role", "Create Role"),
                new Claim("Edit Role", "Edit Role"),
                new Claim("Delete Role", "Delete Role"),
                new Claim("EditStudent", "EditStudent")
            };
            using (var scope = builder.ApplicationServices.CreateScope())
            {
                var dbContext = scope.ServiceProvider.GetService<AppDbContext>();
                var proces = dbContext.Processes.AsQueryable();
                foreach (var item in proces)
                {
                    Claim claim = new Claim(item.ProcName, item.Id.ToString());
                    ClaimsStore.AllClaims.Add(claim);
                }
            }
            return builder;
        }
    }
}
